package de.bht.cge.flightsim.util;

import java.io.File;
import java.io.IOException;

import de.bht.jvr.collada14.loader.ColladaLoader;
import de.bht.jvr.core.Finder;
import de.bht.jvr.core.Geometry;
import de.bht.jvr.core.SceneNode;
import de.bht.jvr.core.ShaderMaterial;
import de.bht.jvr.core.ShaderProgram;
import de.bht.jvr.core.ShapeNode;
import de.bht.jvr.core.Texture2D;
import de.bht.jvr.logger.Log;
import de.bht.jvr.math.Vector3;


public class Helper
{

	
	public static float[] GetNodeTranslation(SceneNode node)
	{
		float[] position = node.getTransform().getMatrix().translation().getData();
		return position;
	}
	
	
	public static Vector3 GetNodeTranslationVector(SceneNode node)
	{
		return new Vector3(GetNodeTranslation(node));
	}
	

	public static ShaderMaterial CreateShaderMaterial(Texture2D texture, ShaderProgram prog, String groupName, String uniformName, String shaderContext)
	{
		//Create the ShaderMaterial
        ShaderMaterial mat = new ShaderMaterial();
        
        //Group the material
        mat.setMaterialClass(groupName);
        
        //Put shader program in AMBIENT-context
        mat.setShaderProgram(shaderContext, prog); 
        
        //Apply the texture
        mat.setTexture(shaderContext, uniformName, texture);
        
        return mat;
	}
	

	
	public static ShaderProgram LoadShader(File vertexShader, File fragmentShader) throws IOException
	{       
        Log.info(Helper.class, "  -> Loading shaders '" + vertexShader.getName() + "' and '" + fragmentShader.getName() + "'"); 
        
        try
        {
        	ShaderProgram sp = new ShaderProgram(vertexShader, fragmentShader);
        	return sp;
        }
        catch (IOException ioEx)
        {
        	ioEx.printStackTrace();
        	throw new IOException("Shader loading failed", ioEx);
        }
        catch (Exception ex)
        {
        	ex.printStackTrace();
        	throw new IOException("Shader loading failed (generic Exception occurred)", ex);
        }        
	}
	
}
